//***************************************************************
//  File:    GameObject.h
//  Date:    12/17/2012
//  Author:  liangxc (liangxc2010@gmail.com)
//-------------------------------------------------------------
//
//-------------------------------------------------------------
//  This file is part of Hare2D Game Engine.
//  Copyright (C) All Rights Reserved
//***************************************************************
//
//***************************************************************
#ifndef __PARTICLECOMPONENT_H__
#define __PARTICLECOMPONENT_H__

#include "GraphicsPrerequisites.h"
#include "Shader.h"
#include "HareGraphicsType.h"

#include "ParticleSprite.h"
#include "Component.h"

#define MAX_PARTICLES 500

namespace hare
{
	class ParticleInfo;

	class GRAPHICS_API ParticleComponent : public Component
	{
		HARE_DECLARE_DYNAMIC_CLASS(ParticleComponent)
	public:
		struct ParticleUnit
		{
			Vector2   location;
			Vector2   velocity;

			float	  gravity;
			float	  radialAccel;
			float	  tangentialAccel;

			float	  spin;
			float	  spinDelta;

			float	  size;
			float	  sizeDelta;

			Color     color;
			Color     colorDelta;

			float	  age;
			float	  terminalAge;
		};

	public:
		ParticleComponent();
		virtual ~ParticleComponent();

		virtual void render(PointF pos, PointF rotation, PointF scale);
		virtual void fire();
		virtual void fireAt(float x, float y);
		virtual void move(float dx, float dy);
		virtual void moveTo(float x, float y);
		virtual void pause();
		virtual void stop();
		virtual void setPosition(float x, float y);

		virtual void postLoaded();
		virtual void postEdited(Attribute* attr);

		void setZ(float z);
		float getZ();

		void setOffset(float x, float y);
		void setOffset(const PointF& off);
		PointF getOffset();

		PointF getPosition();
		void   setMaterial(TextureMtrl* mtrl);

	protected:
		virtual void frameMove();

	protected:
		float  zDepth;
		PointF offset;

		float		age;
		float		emissionResidue;
		Vector2	    prevLocation;
		int		    particlesAlive;

		ParticleInfo::Ptr particleInfo;
		ParticleUnit particleUnits[MAX_PARTICLES];

		Vector2       location;
		TextureMtrl::Ptr particleMtrl;
	};
}


#endif